﻿using Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ColorLife.Core.Helper;
public partial class ThongKe_PageCanBoTheoTuoi : System.Web.UI.Page
{
    public int total = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            BinData();



        }
    }
    public int TuoiHienTai
    {
        get
        {
            if (Request.QueryString["Tuoi"] != null)
                return Request.QueryString["Tuoi"].ToInt();
            return -1;
        }
    }
    void BinData()
    {

        int pageSize = 10;

        int pageNum = 1;
        if (Request.QueryString[PagingControl1.QueryStringKey] != null)
        {
            pageNum = int.Parse(Server.HtmlEncode(Request.QueryString[PagingControl1.QueryStringKey]));
        }
        else pageNum = 1;

        if (Request.QueryString["Tuoi"] != null)
        {
            rptData.DataSource = Paging_CanBo_TheoTuoi(TuoiHienTai, pageSize, pageNum, out total);

            rptData.DataBind();

            PagingControl1.TotalRecord = total;
            PagingControl1.CurrentPage = pageNum;
            PagingControl1.PageSize = pageSize;
            ddlDonVi.SelectedValue = TuoiHienTai.ToString();
        }
    }
    protected void btnRefresh_ServerClick(object sender, EventArgs e)
    {
        Response.Redirect(Request.Url.AbsolutePath);
    }
    public List<CanBo> Paging_CanBo_TheoTuoi(int khoangTuoi, int pageSize, int pageNum, out int total)
    {

        var query = from item in CanBo.All().Where(c => c.TuoiHienTai > khoangTuoi && c.TuoiHienTai < khoangTuoi + 10)
                    select item;
        total = query.Count();
        var list = query.Skip(pageSize * (pageNum - 1)).Take(pageSize).ToList();
        return list;
    }
    protected void ddlDonVi_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("PageCanBoTheoTuoi.aspx?Tuoi=" + ddlDonVi.SelectedValue);
    }
}